package com.maila.xiaoaoschool.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.maila.xiaoaoschool.R;
import com.maila.xiaoaoschool.entity.ScoreGoods;
import com.maila.xiaoaoschool.util.Constants;
import com.maila.xiaoaoschool.util.NullPointUtils;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/9/29.
 */

public class ScoreChangeAdapter extends BaseAdapter {
    Context context;
    List<ScoreGoods.DataBean> mdata;

    public ScoreChangeAdapter(Context context) {
        this.context = context;
        mdata = new ArrayList<>();
    }

    public List<ScoreGoods.DataBean> getMdata() {
        return mdata;
    }

    public void setMdata(List<ScoreGoods.DataBean> mdata) {
        this.mdata = mdata;
    }
    public void addMdata(List<ScoreGoods.DataBean> mdata) {
        this.mdata.addAll(mdata);
    }

    @Override
    public int getCount() {
        return mdata.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_jifen, viewGroup, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
            AutoUtils.autoSize(view);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        Glide.with(context).load(Uri.parse(Constants.URL_ROOT_XIAOAO + mdata.get(i).getImg())).into(holder.ivCash);
        holder.tvGoodCash.setText(mdata.get(i).getTitle());
        if(!NullPointUtils.checknull(mdata.get(i).getCost())&&mdata.get(i).getCost().equals("0.00")){
            holder.llUseMoney.setVisibility(View.GONE);
        }else {
            holder.llUseMoney.setVisibility(View.VISIBLE);
            holder.tvMoney.setText(mdata.get(i).getCost());
        }
        holder.tvNum.setText(mdata.get(i).getScore());
        return view;
    }

    static class ViewHolder {
        @BindView(R.id.iv_cash)
        ImageView ivCash;
        @BindView(R.id.tv_good_cash)
        TextView tvGoodCash;
        @BindView(R.id.tv_num)
        TextView tvNum;
        @BindView(R.id.tv_shop_name)
        TextView tvShopName;
        @BindView(R.id.arl_cash)
        AutoRelativeLayout arlCash;
        @BindView(R.id.tv_money)
        TextView tvMoney;
        @BindView(R.id.ll_use_money)
        AutoLinearLayout llUseMoney;


        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
